<template>
  <div>
    <tree-node v-for="(item, index) in cloneData" :key="index" :data="item" :show-checkbox="showCheckbox" />
  </div>
</template>

<script>
import TreeNode from './node'
import { deepClone } from '@/utils/tool'
export default {
  name: 'Tree',
  components: {
    TreeNode,
  },
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    showCheckbox: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      cloneData: [],
    }
  },
  watch: {
    data() {
      this.rebuildData()
    },
  },
  created() {
    this.rebuildData()
  },
  methods: {
    rebuildData() {
      this.cloneData = deepClone(this.data)
    },
    emitEvent(eventName, data) {
      this.$emit(eventName, data, this.cloneData)
    },
  },
}
</script>
